/*
 * 引用此页面前应先引入common.js
 */

/* 初始化combobox中的下拉框数据*/
function initCombobox() {
	if($("#input_GENDER") != undefined) {
		$("#input_GENDER").combobox({
			panelHeight: "50px",
			valueField: 'value',
			textField: 'text',
			data: [{
				"value": "男",
				"text": "男"
			}, {
				"value": "女",
				"text": "女"
			}]
		})
	}
}

/* 判断数据的完整性，如果存在非必要的字段需要重写此方法*/
function isTrueData() {
	var tip = "验证成功";
	var _value;
	if($("#basicInfo") == undefined) {
		console.log("检查basicInfo是否存在");
		return;
	}
	$("#basicInfo input[name]").each(function(index) {
		_value = $(this).val().trim();
		if(_value.length == 0) {
			tip = "请将数据填写完整";
			return;
		}
	});
	return tip;
}

/*判断数据格式是否正确*/
function checkDataFormat() {
	if($(".checkIdcard") == undefined && $(".checkPhone") != undefined) {
		console.log("请检查是否存在checkIdcard和checkPhone");
		return;
	}
	var tip = "验证成功";
	var _value;
	$(".chechkPhone").each(function(index) {
		_value = $(this).val().trim();
		if(_value.length != 0) {
			tip = checkPhoneNumber(_value);
			if(tip != "验证成功") {
				return;
			}
		}
	});
	if(tip !== "验证成功") {
		return tip;
	}
	if($(".checkIdcard") != undefined) {
		$(".checkIdcard").each(function(index) {
			_value = $(this).val().trim();
			if(_value.length != 0) {
				tip = IdentityCodeValid(_value);
				if(tip != "验证成功") {
					return;
				}
			}
		});
	}
	return tip;
}

/*清空dialog中的数据，再点击新建或者构建dialog数据的时候调用*/
function resetData() {
	if($("#img") != undefined){
		$("#img").removeAttr("src");//处理头像
	}
	if($("#ff") != undefined) {
		$("#ff").form("reset"); //清空form中的数据
	}
	if($("span[name]") == undefined) {
		console.log("请检查是否有需要执行的span");
		return;
	}
	$("span[name]").each(function(index) {
		name = $(this).attr("name");
		if(name != undefined || name != "") {
			$(this).text("");
		}
	});
	$("#verifydisplay").empty();//处理审核图片
//	verifyStatus_Market("0", false);
}
/*提交数据*/

function submitDialogData() {
	var _data = {};
	$("#ff .easyui-combobox").each(function(index) {
		var s = $(this).attr("id");
		var subtr = deletePreSymbol("input_", s);
		_data[subtr] = $(this).combobox("getValue").trim();
	});
	$("#ff .easyui-textbox").each(function(index) {
		var s = $(this).attr("id");
		var subtr = deletePreSymbol("input_", s);
		_data[subtr] = $(this).textbox("getValue").trim();
	});
	$("#ff .easyui-datebox").each(function(index) {
		var s = $(this).attr("id");
		var subtr = deletePreSymbol("input_", s);
		_data[subtr] = $(this).datebox("getValue").trim();
	});
	$("#ff .easyui-numberbox").each(function(index) {
		var s = $(this).attr("id");
		var subtr = deletePreSymbol("input_", s);
		_data[subtr] = $(this).textbox("getValue").trim();
		if($(this).textbox("getValue").trim().length == 0){
			_data[subtr] = "0";
		}
	});
	$("#ff span[name]").each(function(index) {
		_name = $(this).attr("name");
		if(_name != null) {
			_value = $(this).text();
			_data[_name] = _value;
		}
	});
	return _data;
}

/*构建dialog中的数据*/
function getDialogData(data) {
	if(typeof(data) == "undefined") {
		console.log("该网页无数据！");
	}
	resetData();
	$("#ff .easyui-textbox").each(function(index) {
		var s = $(this).attr("id");
		var substr = deletePreSymbol("input_", s);
		if(typeof(data[substr]) != "undefined") {
			$(this).textbox("setValue", data[substr]);
		}
	});
	$("#ff .easyui-combobox").each(function(index) {
		var s = $(this).attr("id");
		var substr = deletePreSymbol("input_", s);
		if(typeof(data[substr]) != "undefined") {
			$(this).combobox("setValue", data[substr]);
		}
	});
	$("#ff .easyui-datebox").each(function(index) {
		var s = $(this).attr("id");
		var substr = deletePreSymbol("input_", s);
		if(typeof(data[substr]) != "undefined") {
			$(this).textbox("setValue", data[substr]);
		}
	});
	$("#ff .easyui-numberbox").each(function(index) {
		var s = $(this).attr("id");
		var substr = deletePreSymbol("input_", s);
		if(typeof(data[substr]) != "undefined") {
			$(this).textbox("setValue", data[substr]);
		}
	});
	$("span[name]").each(function(index) {
		var name = $(this).attr("name");
		if(data[name] != undefined) {
			$(this).text(data[name]);
		}
	});
}
////删除 id 中input_的前缀
function deletePreSymbol(_presymbol, _str) {
	var len = _str.length;
	var pre_symbol_len = _presymbol.length;
	var _substr = _str.substring(pre_symbol_len, len);
	return _substr;
}